/* JSON 对比工具专用样式 */

.json-comparator {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--bg-secondary);
}

/* 头部区域 */
.comparator-header {
    display: flex;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    padding: 16px 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    align-items: center;
}

.panel-header {
    flex: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header h3 {
    margin: 0;
    color: var(--text-primary);
    font-size: 18px;
    font-weight: 600;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.stats {
    font-size: 14px;
    color: var(--text-secondary);
    min-width: 120px;
    text-align: right;
}

.diff-summary-container {
    flex: 0 0 auto;
    margin-left: 20px;
}

.diff-summary-text {
    font-size: 14px;
    color: var(--text-primary);
    font-weight: 500;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-radius: 4px;
    white-space: nowrap;
}



/* 按钮样式 */
.btn-primary {
    background: #007bff;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-primary:hover {
    background: #0056b3;
}

.btn-secondary {
    background: #6c757d;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-secondary:hover {
    background: #545b62;
}

/* 主体区域 */
.comparator-body {
    display: flex;
    flex: 1;
    gap: 0;
    min-height: 0;
}

.json-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    min-width: 0;
}

.json-panel:last-child {
    border-right: none;
}

/* 编辑器容器 */
.editor-container {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
}

/* 行号区域 */
.line-numbers {
    position: absolute;
    top: 16px;
    left: 16px;
    width: 40px;
    height: calc(100% - 32px);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 14px;
    line-height: 1.6;
    text-align: right;
    color: var(--text-secondary);
    pointer-events: none;
    z-index: 4;
    overflow: hidden;
}

.line-numbers .line-number {
    display: block;
    padding-right: 5px;
}

/* JSON 编辑器 */
.json-editor {
    flex: 1;
    width: 100%;
    padding: 16px 16px 16px 60px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 14px;
    line-height: 1.6;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text-primary);
    resize: none;
    min-height: 400px;
    position: relative;
    z-index: 3;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: break-word;
    overflow-x: auto;
    word-wrap: break-word;
}

.json-editor::placeholder {
    color: var(--text-secondary);
    font-style: italic;
}

.json-editor:focus {
    background: transparent;
    box-shadow: inset 0 0 0 2px #007bff;
}

/* 高亮覆盖层 */
.highlight-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 16px 16px 16px 60px; /* 左侧留出行号空间 */
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 14px;
    line-height: 1.6;
    pointer-events: none;
    overflow: scroll; /* 允许滚动以同步编辑器 */
    z-index: 2; /* 确保在编辑器下方 */
    white-space: pre-wrap; /* 保留格式，但允许长行换行 */
    word-break: break-word; /* 在单词边界换行，但必要时也会断开单词 */
    overflow-wrap: break-word; /* 允许在单词内换行 */
    overflow-x: auto; /* 允许水平滚动，与编辑器保持一致 */
    word-wrap: break-word; /* 兼容旧浏览器 */
    background: transparent;
    color: transparent; /* 文字透明，只显示背景色 */
    /* 隐藏滚动条 */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

/* 隐藏 overlay 的滚动条 (Webkit) */
.highlight-overlay::-webkit-scrollbar {
    display: none;
}

.highlight-overlay .diff-line {
    display: block;
    margin: 0 -16px;
    padding: 0 16px;
}

/* 按照图片颜色方案设置差异高亮 */
.highlight-overlay .diff-added,
.highlight-overlay div.diff-added,
.highlight-overlay .diff-line.diff-added,
#highlightOverlay1 .diff-added,
#highlightOverlay2 .diff-added {
    background-color: #d4edda !important;
    border-left: 4px solid #28a745 !important;
}

.highlight-overlay .diff-removed,
.highlight-overlay div.diff-removed,
.highlight-overlay .diff-line.diff-removed,
#highlightOverlay1 .diff-removed,
#highlightOverlay2 .diff-removed {
    background-color: #f8d7da !important;
    border-left: 4px solid #dc3545 !important;
}

.highlight-overlay .diff-modified,
.highlight-overlay div.diff-modified,
.highlight-overlay .diff-line.diff-modified,
#highlightOverlay1 .diff-modified,
#highlightOverlay2 .diff-modified {
    background-color: rgba(133, 133, 0, 0.3) !important;
    border-left: 4px solid #858500 !important;
}

/* 强制高亮样式 - 确保显示 */
.diff-added {
    background-color: #d4edda !important;
    border-left: 4px solid #28a745 !important;
}

.diff-removed {
    background-color: #f8d7da !important;
    border-left: 4px solid #dc3545 !important;
}

.diff-modified {
    background-color: rgba(133, 133, 0, 0.3) !important;
    border-left: 4px solid #858500 !important;
}

/* JSON 错误提示 */
.json-error {
    background: #f8d7da;
    color: #721c24;
    padding: 8px 16px;
    font-size: 12px;
    border-top: 1px solid #f5c6cb;
    display: none;
    flex-shrink: 0;
}

body.dark-theme .json-error {
    background: #5a1f1f;
    color: #f8d7da;
    border-top: 1px solid #721c24;
}

.json-error.show {
    display: block;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .comparator-header {
        flex-direction: column;
        gap: 16px;
    }
    
    .comparator-toolbar {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }
    
    .comparator-body {
        flex-direction: column;
    }
    
    .json-panel {
        border-right: none;
        border-bottom: 1px solid #e9ecef;
    }
}

/* 滚动条样式 */
.json-editor::-webkit-scrollbar,
.highlight-overlay::-webkit-scrollbar {
    width: 8px;
}

.json-editor::-webkit-scrollbar-track,
.highlight-overlay::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 4px;
}

.json-editor::-webkit-scrollbar-thumb,
.highlight-overlay::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.json-editor::-webkit-scrollbar-thumb:hover,
.highlight-overlay::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}